package com.yfree.global

import com.yfree.config.YConfig
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler

@ControllerAdvice
class YGlobalExceptionHandler : YController() {
//    @ResponseBody
//    @ExceptionHandler(Exception::class)
//    fun error(e: Exception): Any {
//        return json(0, message = e.localizedMessage)
//    }

    @ExceptionHandler(Exception::class)
    fun errorPage(e: Exception): String {
        val errorCallBack = YConfig.Response.errorCallBack(e)
        return if (errorCallBack.isNotEmpty())
            errorCallBack
        else
            """
                <!DOCTYPE html>
                <html>
                <head>
                    <title>YError</title>
                </head>
                <body>
                    ${if (!YConfig.DEBUG) "访问错误" else e.localizedMessage}
                </body>
                </html>
            """
    }
}
